local dir `c(pwd)'
local g=`1'
qui {
clear
set obs 1
foreach type in original order structure {
gen entropy_`type'=.
gen words_`type'=.
gen chars_`type'=.
}
gen book=.             
gen str translation=""	                        
save  entropy_bible_`g', replace

use calculation_`g', clear

local till=_N
local counter=_N

forvalues i=1/`till' {
	use calculation_`g', clear
	local translation=translation[`i']
	local counter=`counter'-1
	
	noisily di "`translation' (left: `counter') "
    	
	foreach book in 100		{			
		foreach type in original order structure {					
			import delimited `"`dir'\\shortestmismatches_validation_VI\\`translation'_`book'_`type'.txt.sm.txt"', delimiter(tab) varnames(nonames) stripquote(no) bindquotes(nobind) case(preserve) encoding(UTF-8) clear   
			local chars_`type'_`book'=_N
			gen words=1 if v1==" "
			sum words if words==1
			local words_`type'_`book'=r(N)
			ren v2 li
			gen i=_n
			local n=_N
			gen tosum=(li)/(log(i)/log(2))
			sum tosum
			local entropy_`type'_`book'=r(sum)
		}
	}
	
	foreach book in 100		{			
		use  entropy_bible_`g', clear
					local new=_N+1
					set obs `new'
					local in `"in `new'"'
					foreach type in original order structure {
							replace entropy_`type'=`entropy_`type'_`book'' 	`in'
							replace chars_`type'=`chars_`type'_`book'' 			`in'
							replace words_`type'=`words_`type'_`book'' 			`in'
							}   
					replace book=`book'                     			`in'      		
					replace translation="`translation'"	          	`in'  
					save  entropy_bible_`g', replace
				}
			}
/* generate finished file */
clear
set obs 1
gen v=1
save finished_`g', replace
}

clear         
exit, STATA 	
